var login = require('../../service/login');
module.exports = {
    login: async function (req, res, next) {
        console.log(req.body);
        const {username, password} = {
            username: req.body.username,
            password: req.body.password
        };
        console.log(req.body);
        try {
            if (!username) {
                throw new Error('账号参数错误');
            } else if (!password) {
                throw new Error('密码参数错误');
            } else if (username.length < 5) {
                throw  new Error('账号至少得5个字符')
            } else if (password.length < 5) {
                throw  new Error('密码必须6到12位')
            }
        } catch (err) {
            res.render('login', {msg: err.message, title: '登录'});
            return;
        }
        await login.singin(req).then(function (rs) {
            res.redirect("/");
        }, function (err) {
            res.render('login', {msg: err.message, title: '登录'});
        });
    }
};